<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .custom-form {
      width: 500px;
      margin: 100px auto 0;
      border: 1px solid #2487c9;
    }

    .form-title {
      padding: 10px 0;
      font-size: 18px;
      color: #fff;
      background-color: #2487c9;
      text-align: center;
      margin-bottom: 15px;
    }

    .form-lable {
      display: flex;
      height: 48px;
      line-height: 48px;
      padding: 0 10px;
    }

    .lable-title {
      width: 80px;
      margin-right: 10px;
      text-align: right;
    }

    .lable-input {
      flex: 1;
    }

    .lable-text {
      display: block;
      width: 100%;
      height: 36px;
      margin: 6px 0;
      padding: 0 15px;
      font-size: 16px;
      box-sizing: border-box;
      border: 1px solid #2487c9;
      outline: none;
      border-radius: 4px;
    }

    .lable-text:focus {
      background-color: #eee;
    }

    .lable-btn {
      padding: 8px 40px;
      font-size: 18px;
      color: #fff;
      background-color: #2487c9;
      border: none;
      border-radius: 4px;
    }
  </style>
</head>

<body>
  <div id="box"></div>
  <!-- <form action="#" method="post" class="custom-form">
    <div class="form-title">个人信息</div>
    <div class="form-lable">
      <div class="lable-title">用户名</div>
      <div class="lable-input">
        <input type="text" name="username" class="lable-text">
      </div>
    </div>
    <div class="form-lable">
      <div class="lable-title">用户名</div>
      <div class="lable-input">
        <input type="text" name="username" class="lable-text">
      </div>
    </div>
    <div class="form-lable">
      <div class="lable-title">用户名</div>
      <div class="lable-input">
        <input type="text" name="username" class="lable-text">
      </div>
    </div>
    <div class="form-lable">
      <div class="lable-title"></div>
      <div class="lable-input">
        <input type="submit"value="提交" class="lable-btn">
      </div>
    </div> -->
  </form>
  <script>
    var elements = [
      { tag: 'input', text: '用户名', attr: { type: 'text', name: 'username' } },
      { tag: 'input', text: '密码', attr: { type: 'password', name: 'userpass' } },
      { tag: 'input', text: '确认密码', attr: { type: 'password', name: 'userpass_confirm' } },
      { tag: 'input', attr: { type: 'submit', value: '提交' } }
    ];

    function Form(data) {
      this.data = data;
    }
    Form.prototype.createForm = function () {
      var _data = this.data;
      var _html = '<form action="#" method="post" class="custom-form"><div class="form-title">个人信息</div>';
      for (let i in _data) {
        let _text = _data[i]['text'] ? _data[i]['text'] : '';
        let _value = _data[i]['attr']['value'] ? _data[i]['attr']['value'] : '';
        let _class = _value ? 'lable-btn' : 'lable-text';
        _html += '<div class="form-lable"><div class="lable-title">' + _text + '</div><div class="lable-input"><input type="' + _data[i]['attr']['type'] + '" name="' + _data[i]['attr']['name'] + '" class="' + _class + '"></div></div>'
      }
      _html += '</form>';
      return _html;
    }
    var form01 = new Form(elements);
    document.getElementById('box').innerHTML = form01.createForm();
  </script>
</body>

</html>